#include "UserDao.h"

int main() 
{
    auto pool = std::make_shared<MySqlPool>();

    UserDao userDao(pool);

    // 插入
    // if (userDao.InsertUser("lala", "lala@example.com", "pwd123")) {
    //     std::cout << "插入用户成功！\n";
    // }
    // else 
    // {
    //     std::cerr << "插入用户失败！\n";
    //     return -1;
    // }

    // 查询
    auto users = userDao.GetAllUsers();
    for (auto& row : users) {
        std::cout << "id=" << row["id"] 
                  << ", name=" << row["name"] 
                  << ", email=" << row["email"] 
                  << ", pwd = " << row["pwd"] << "\n";
    }

    // 根据邮箱查询
    auto user = userDao.GetUserByEmail("lala@example.com");
    if (!user.empty()) {
        std::cout << "id=" << user["id"] 
                  << ", name=" << user["name"] 
                  << ", pwd = " << user["pwd"] 
                  << ", email=" << user["email"] << "\n";
    }

    // 根据用户名查询
    user = userDao.GetUserByName("lala");
    if (!user.empty()) {
        std::cout << "id=" << user["id"] 
                  << ", name=" << user["name"] 
                  << ", email=" << user["email"] << "\n";
    }

}